package com.qcnh.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qcnh.entity.Announcement;
import com.qcnh.entity.Payment;
import com.qcnh.mapper.AnnouncementMapper;
import com.qcnh.service.AnnouncementService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import unil.Result;

import java.util.List;

/**
 * <p>
 * 公告表 服务实现类
 * </p>
 */
@Service
public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Announcement> implements AnnouncementService {

    @Autowired
    private AnnouncementMapper announcementMapper;

    //分页查询公告并支持根据公告标题进行模糊查询
    @Override
    public IPage<Announcement> selectAllAnnouncements(Integer current, Integer size, String keyWord) {
        Page<Announcement> page = new Page<>(current,size);//创建分页对象
        QueryWrapper<Announcement> wrapper = new QueryWrapper<>();//创建查询对象
        if(StringUtils.isNotBlank(keyWord))//判空处理并模糊查询
            wrapper.like("title",keyWord);
        return announcementMapper.selectPage(page, wrapper);
    }
   //添加公告
    @Override
    public Boolean addAnnouncement(Announcement announcement) {
        return announcementMapper.insert(announcement)>0?true:false;
    }

    //根据公告id集合批量删除公告
    @Override
    public Boolean delAnnouncementsByIdList(List<Integer> announcementIds) {
         return announcementMapper.deleteBatchIds(announcementIds)>0?true:false;
    }

    //更新公告信息
    @Override
    public Boolean updateAnnouncement(Announcement announcement) {
        return announcementMapper.updateById(announcement)>0?true:false;
    }
}
